﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using fcwms.Common;
using System.Text;

public partial class admin_user_user_pwd : SessionManage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            fcwms.Model.dt_users model = GetAdminInfo();
            ShowInfo(model.id);

            //txtID.Text = Session["username"].ToString();
            //string userID = txtID.Text.ToString().Trim();

            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("select * from dt_users  ");
            //strSql.Append("where user_id=@user_id");
            //SqlParameter[] parms = new SqlParameter[] { 
            //    new SqlParameter("@user_id", userID)};
            ////DataSet ds = DbHelperSQL.Query(strSql.ToString(),parms);
            //DataTable ds = DbHelperSQL.Query(strSql.ToString(), parms).Tables[0];
            //txtOldPwd.Attributes["value"] = ds.Rows[0]["user_pwd"].ToString();
            //txtOldPwd.Enabled = false;
            //txtRealName.Text = ds.Rows[0]["user_name"].ToString();
            //txtBranch.Text = ds.Rows[0]["user_branch"].ToString();
            //txtBranch.Enabled = false;
            //txtTelephone.Text = ds.Rows[0]["telephone"].ToString();
            //txtEmail.Text = ds.Rows[0]["email"].ToString();
        }
    }

    #region 赋值操作==============================
    private void ShowInfo(int _id)
    {
        fcwms.BLL.dt_users bll = new fcwms.BLL.dt_users();
        fcwms.Model.dt_users model = bll.GetModel(_id);
        txtID.Text = model.user_id;
        txtOldPwd.Attributes["value"] = model.user_pwd; ;
        txtOldPwd.Enabled = false;
        txtRealName.Text = model.user_name;
        txtBranch.Text = new fcwms.BLL.dt_branch().GetTitle(model.branch_id);
        txtBranch.Enabled = false;
        txtTelephone.Text = model.telephone;
        txtEmail.Text = model.email;
    }
    #endregion

    #region 保存操作==============================
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        fcwms.BLL.dt_users bll = new fcwms.BLL.dt_users();
        fcwms.Model.dt_users model = GetAdminInfo();
        if (txtUserPwd.Text.Trim() != txtShowPwd.Text.Trim())
        {
            MessageBox.Jscript(this, "两次密码不一致！", "", "Warning");
            return;
        }
        model.user_pwd = DESEncrypt.Encrypt(txtShowPwd.Text.Trim());
        model.user_name = txtRealName.Text.Trim();
        model.telephone = txtTelephone.Text.Trim();
        model.email = txtEmail.Text.Trim();
        if (!bll.Update(model))
        {
            MessageBox.Jscript(this, "保存过程中发生错误啦！", "", "Error");
            return;
        }
        //Session[DTKeys.SESSION_ADMIN_INFO] = null;
        MessageBox.Jscript(this, "信息保存成功啦！", "user_pwd.aspx", "Success");

        //string userPwd = DESEncrypt.Encrypt(txtShowPwd.Text.Trim());
        //if (txtUserPwd.Text.Trim() != txtShowPwd.Text.Trim())
        //{
        //    MessageBox.Jscript(this, "两次密码不一致！", "", "Warning");
        //    return;
        //}
        //StringBuilder strSql = new StringBuilder();
        //strSql.Append("update dt_users set user_pwd=@user_pwd,");
        //strSql.Append("user_name=@user_name,user_branch=@user_branch,");
        //strSql.Append("telephone=@telephone,email=@email ");
        //strSql.Append("where user_id=@user_id");
        //SqlParameter[] parms = new SqlParameter[]{
        //    new SqlParameter("@user_id",txtID.Text.Trim()),
        //    new SqlParameter("@user_pwd",userPwd),
        //    new SqlParameter("@user_name",txtRealName.Text.Trim()),
        //    new SqlParameter("@user_branch",txtBranch.Text.Trim()),
        //    new SqlParameter("@telephone",txtTelephone.Text.Trim()),
        //    new SqlParameter("@email",txtEmail.Text.Trim())};
        ////成功显示提示并跳转
        //if (DbHelperSQL.ExecuteSql(strSql.ToString(), parms) > 0)
        //{
        //    MessageBox.Jscript(this, "信息保存成功啦！", "user_pwd.aspx", "Success");
        //}
    } 
    #endregion
}